import React, {Component} from 'react';
import axios from "axios";
class App extends Component {
    getStudentsData = ()=>{
        // 这里要配置代理,不然会跨域
        axios.get('http://localhost:3000/api1/students').then(
            response=>console.log('请求的数据为:',response.data),
            error=>console.log('请求失败了',error)

        )
    }

    getCarsData = ()=>{
        // 这里要配置代理,不然会跨域
        axios.get('http://localhost:3000/api2/cars').then(
            response=>console.log('请求的数据为:',response.data),
            error=>console.log('请求失败了',error)

        )
    }
    render() {
        return (
            <div>
                <button onClick={this.getStudentsData}>获取学生信息</button>
                <button onClick={this.getCarsData}>获取汽车的信息</button>

            </div>
        );
    }
}

export default App;
